package com.zkt.recommend.application.controller;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson2.JSON;
import com.zkt.recommend.application.dto.RecommendReqDTO;
import com.zkt.recommend.common.entity.Result;
import com.zkt.recommend.domain.service.RecommendDomainService;
import com.zkt.recommend.infra.basic.entity.SubjectInfo;
import com.zkt.subject.entity.SubjectInfoDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 赵开泰
 * @program jc-club
 * @date 2025/3/27
 * @description 推荐controller层
 **/

@RestController
@RequestMapping("/recommend")
@Slf4j
public class RecommendController {
	
	@Resource
	private RecommendDomainService recommendDomainService;
	
	/**
	 * 获取推荐题目
	 *
	 * @param req 推荐参数
	 * @return 推荐的题目
	 */
	@PostMapping("getRecommedSubject")
	public Result<List<SubjectInfoDTO>> getRecommendSubject(@RequestBody RecommendReqDTO req) {
		try {
			if (log.isInfoEnabled()) {
				log.info("RecommendController.getRecommendSubject.req:{}", JSON.toJSONString(req));
			}
			
			boolean hasLabel = false;
			if (CollUtil.isNotEmpty(req.getLabelIds())) {
				hasLabel = true;
			}
			
			return Result.ok(recommendDomainService.getRecommendSubject(req.getLabelIds(), hasLabel, req.getNum()));
		} catch (Exception e) {
			log.error("RecommendController.getRecommendSubject.error:{}", e.getMessage(), e);
			return Result.fail("获取推荐题目失败");
		}
	}
	
}